package com.flight.trans.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.LeavePortWeightingBean.LeavePortWeightingData;
import com.flight.trans.util.LogUtils;

import java.util.List;

/**
 * 出港称重
 */
public class LeavePorWeighingAdapter extends BaseRecyclerAdapter<LeavePortWeightingData> {

    private boolean IsDone ;

    public LeavePorWeighingAdapter(Context mContext, List<LeavePortWeightingData> mList , boolean IsDone) {
        super(mContext, mList);
        this.IsDone = IsDone ;
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_leave_port_weighting;
    }

    @Override
    protected void bindData(BaseViewHolder holder, LeavePortWeightingData data, int position) {
        LinearLayout mLlContainerItem = holder.findViewById(R.id.mLlContainerItem);

        TextView mTvContainerNo = holder.findViewById(R.id.mTvContainerNo);//容器编号
        TextView mTvFlightNumber = holder.findViewById(R.id.mTvFlightNumber);//航班号
        TextView mTvFlightDate = holder.findViewById(R.id.mTvFlightDate);//日期
        TextView mTvOrderCount = holder.findViewById(R.id.mTvOrderCount);//运单数量
        TextView mTvOrderNumber = holder.findViewById(R.id.mTvOrderNumber);//运单件数
        TextView mTvOrderWeight = holder.findViewById(R.id.mTvOrderWeight);//货邮重量
        TextView mTvContainerWeight = holder.findViewById(R.id.mTvContainerWeight);//容器重量
        TextView mTvTotalWeight = holder.findViewById(R.id.mTvTotalWeight);//总重量
        TextView mTvWeightingWeight = holder.findViewById(R.id.mTvWeightingWeight);//称重重量
        TextView mTvWeighingPerson = holder.findViewById(R.id.mTvWeighingPerson);//称重人

        mTvContainerNo.setText(data.getContainerCode());

        if(data.getFlightNo().contains(",")){
            mTvFlightNumber.setText(data.getFlightNo().replace(",", "\n"));
        }else {
            mTvFlightNumber.setText(data.getFlightNo());
        }

        if(data.getFlightDate().contains(",")){
            mTvFlightDate.setText(data.getFlightDate().replace(",", "\n"));
        }else {
            mTvFlightDate.setText(data.getFlightDate());
        }

        mTvOrderCount.setText(String.valueOf(data.getOrderNum()));
        mTvOrderNumber.setText(String.valueOf(data.getGoodsNum()));
        mTvOrderWeight.setText(String.valueOf(data.getGoodsWeight()));
        mTvContainerWeight.setText(String.valueOf(data.getContainerWeight()));
        mTvTotalWeight.setText(String.valueOf(data.getGoodsWeight() + data.getContainerWeight()));
        mTvWeightingWeight.setText(String.valueOf(data.getWeight()));
        mTvWeighingPerson.setText(!TextUtils.isEmpty(data.getWeighingName()) ? data.getWeighingName() : "");

        mTvWeightingWeight.setVisibility(IsDone ? View.VISIBLE : View.GONE);
        mTvWeighingPerson.setVisibility(IsDone ? View.VISIBLE : View.GONE);

        setOnItemClickListener(mLlContainerItem , position);
    }

    /**
     * 刷新填充器
     * @param mList
     */
    public void updateAdapter(List<LeavePortWeightingData> mList , boolean isDone){
        this.mList = mList ;
        this.IsDone = isDone ;
        notifyDataSetChanged();
    }
}
